package 天梯赛.A.A8;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.nextLine();
        for (int i = 0; i < m; i++) {
            String str = sc.nextLine();
            int x = 1;
            for (int j = 0; j < str.length() - 1; j++) {
                char ch = str.charAt(j);
                if (ch == 'y') {
                    x = x * 2;
                } else {
                    x = x * 2 + 1;
                }
            }
            int sum = (int) Math.pow(2, n);
            int sum2 = (int) Math.pow(2, n - 1);
            int begin = sum - sum2;
//            System.out.println(begin);
            int jiange=x-begin;
          //  System.out.println(jiange);
            if (str.charAt(str.length()-1) == 'y') {
                System.out.println(jiange*2+1);
            }else{
                System.out.println(jiange*2+2);
            }
        }
    }
}
